﻿using MediatR;
using RBAC.Domain;
using RBAC.Domain.Service.Interfae;
using RBACDuYaJun.Api.Appliction.Command.RoleCommand;

namespace RBACDuYaJun.Api.Appliction.CommandHandlers.RoleHanders
{
    /// <summary>
    /// 角色添加操作
    /// </summary>
    public class RoleCreateCommandHandler : IRequestHandler<RoleCreateCommand, int>
    {
        /// <summary>
        /// 角色服务
        /// </summary>
        private readonly IRoleService _roleService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleService"></param>
        public RoleCreateCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }
        /// <summary>
        /// 角色添加方法（异步）
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(RoleCreateCommand request, CancellationToken cancellationToken)
        {
          return await _roleService.AddRoles(new Roles() { roleName = request.RoleName,addName="张三",addDate=DateTime.Now });
        }
    }
}
